home *** CD-ROM | disk | FTP | other *** search
/ Programming Windows (5th Edition) / Programming Windows, 5th ed. - Companion CD (097-0002183)(1999).iso / Chap09 / PopPad1 / PopPad1.c next >
Encoding:
C/C++ Source or Header  |  1998-10-09  |  3.1 KB  |  94 lines

  1. /*-------------------------------------------------------
  2.    POPPAD1.C -- Popup Editor using child window edit box
  3.                 (c) Charles Petzold, 1998
  4.   -------------------------------------------------------*/
  5.  
  6. #include <windows.h>
  7.  
  8. #define ID_EDIT     1
  9.  
  10. LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
  11.  
  12. TCHAR szAppName[] = TEXT ("PopPad1") ;
  13.  
  14. int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
  15.                     PSTR szCmdLine, int iCmdShow)
  16. {
  17.      HWND     hwnd ;
  18.      MSG      msg ;
  19.      WNDCLASS wndclass ;
  20.      
  21.      wndclass.style         = CS_HREDRAW | CS_VREDRAW ;
  22.      wndclass.lpfnWndProc   = WndProc ;
  23.      wndclass.cbClsExtra    = 0 ;
  24.      wndclass.cbWndExtra    = 0 ;
  25.      wndclass.hInstance     = hInstance ;
  26.      wndclass.hIcon         = LoadIcon (NULL, IDI_APPLICATION) ;
  27.      wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW) ;
  28.      wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
  29.      wndclass.lpszMenuName  = NULL ;
  30.      wndclass.lpszClassName = szAppName ;
  31.      
  32.      if (!RegisterClass (&wndclass))
  33.      {
  34.           MessageBox (NULL, TEXT ("This program requires Windows NT!"),
  35.                       szAppName, MB_ICONERROR) ;
  36.           return 0 ;
  37.      }
  38.      
  39.      hwnd = CreateWindow (szAppName, szAppName,
  40.                           WS_OVERLAPPEDWINDOW,
  41.                           CW_USEDEFAULT, CW_USEDEFAULT,
  42.                           CW_USEDEFAULT, CW_USEDEFAULT,
  43.                           NULL, NULL, hInstance, NULL) ;
  44.      
  45.      ShowWindow (hwnd, iCmdShow) ;
  46.      UpdateWindow (hwnd) ; 
  47.      
  48.      while (GetMessage (&msg, NULL, 0, 0))
  49.      {
  50.           TranslateMessage (&msg) ;
  51.           DispatchMessage (&msg) ;
  52.      }
  53.      return msg.wParam ;
  54. }
  55.  
  56. LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  57. {
  58.      static HWND hwndEdit ;
  59.      
  60.      switch (message)
  61.      {
  62.      case WM_CREATE :
  63.           hwndEdit = CreateWindow (TEXT ("edit"), NULL,
  64.                          WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL |
  65.                                    WS_BORDER | ES_LEFT | ES_MULTILINE |
  66.                                    ES_AUTOHSCROLL | ES_AUTOVSCROLL,
  67.                          0, 0, 0, 0, hwnd, (HMENU) ID_EDIT,
  68.                          ((LPCREATESTRUCT) lParam) -> hInstance, NULL) ;
  69.           return 0 ;
  70.           
  71.      case WM_SETFOCUS :
  72.           SetFocus (hwndEdit) ;
  73.           return 0 ;
  74.           
  75.      case WM_SIZE : 
  76.           MoveWindow (hwndEdit, 0, 0, LOWORD (lParam), HIWORD (lParam), TRUE) ;
  77.           return 0 ;
  78.           
  79.      case WM_COMMAND :
  80.           if (LOWORD (wParam) == ID_EDIT)
  81.                if (HIWORD (wParam) == EN_ERRSPACE || 
  82.                          HIWORD (wParam) == EN_MAXTEXT)
  83.  
  84.                     MessageBox (hwnd, TEXT ("Edit control out of space."),
  85.                                 szAppName, MB_OK | MB_ICONSTOP) ;
  86.           return 0 ;
  87.                
  88.      case WM_DESTROY :
  89.           PostQuitMessage (0) ;
  90.           return 0 ;
  91.      }
  92.      return DefWindowProc (hwnd, message, wParam, lParam) ;
  93. }
  94.